package com.sinvo.oa.util;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.sinvo.oa.result.R;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Description 响应工具类 用于返回数据
 */
public class ResponseUtil {
    public static void out(HttpServletResponse response, R res) {
        ObjectMapper mapper = new ObjectMapper();
        //编码格式
        response.setCharacterEncoding("utf-8");
        //响应码
        response.setStatus(HttpStatus.OK.value());
        //类型
        response.setContentType(MediaType.APPLICATION_JSON_VALUE);
        try {
            //打印数据
            mapper.writeValue(response.getWriter(), res);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
